package com.step.mesh;

public class Color {
	public short r;
	public short g;
	public short b;
	public short a;
	
	public Color(){
		this.r = (short)255;
		this.g = (short)255;
		this.b = (short)255;
		this.a = (short)255;
	}
	
	public Color(short r, short g, short b, short a) {
		this.r = r;
		this.g = g;
		this.b = b;
		this.a = a;
	}

	public Color(float r, float g, float b, float a) {
		this.r = (short)(r * 255);
		this.g = (short)(g * 255);
		this.b = (short)(b * 255);
		this.a = (short)(a * 255);
	}
	
	public Color(int r, int g, int b, int a) {
		this.r = (short)r;
		this.g = (short)g;
		this.b = (short)b;
		this.a = (short)a;
	}
	
	/**
	 * 设置32位rgba值,例如0xFF0000FF;
	 * @param rgba32
	 */
	public void set(long rgba32){		
		this.r = (short) ((rgba32 >> 24) & 0x000000FF);
		this.g = (short) ((rgba32 >> 16) & 0x000000FF);
		this.b = (short) ((rgba32 >> 8) & 0x000000FF);	
		this.a = (short) ((rgba32) & 0x000000FF);
	}
	
	public void set(short r, short g, short b, short a) {
		this.r = r;
		this.g = g;
		this.b = b;
		this.a = a;
	}

	public void set(float r, float g, float b, float a) {
		this.r = (short)(r * 255);
		this.g = (short)(g * 255);
		this.b = (short)(b * 255);
		this.a = (short)(a * 255);
	}
	
	public void set(int r, int g, int b, int a) {
		this.r = (short)r;
		this.g = (short)g;
		this.b = (short)b;
		this.a = (short)a;
	}
	
	public void set(Color color) {
		this.set(color.r, color.g, color.b, color.a);
	}
	
	public Color clone(){
		return new Color(r, g, b, a);
	}
	
	@Override
	public String toString()	{
		return "r:" + r + ", g:" + g + ", b:" + b + ", a:" + a;
	}

	float[] array;
	public float[] toArray() {
		if(array == null) array = new float[4];
		array[0] = r;
		array[1] = g;
		array[2] = b;
		array[3] = a;
		return array;
	}
}
